<template>
  <div class="switch-company">
    <el-switch :value="row[preset.status]"
               :active-value="1"
               :inactive-value="0"
               @change="handleSwitch">
    </el-switch>
  </div>
</template>

<script>
import { equipment } from "@/api/index";

export default {
  name: "SwitchCompany",
  inject: ["$table"],
  props: {
    row: {
      type: Object,
      default: () => { }
    },
    preset: {
      type: Object,
      default: () => { }
    }
  },
  methods: {
    handleSwitch (value) {
      const { iMEICode } = this.row;
      const params = { deviceCode: iMEICode, inHome: value };
      this.$confirm(
        `${value === "1" ? `是否在公司？` : `是否不在公司？`}`,
        "提示"
      )
        .then(async (res) => {
          let response = await equipment.changeStatus(params);
          this.$nextTick(() => {
            this.$message.success(response.message);
            // 刷列表 
            this.$table.search();
          });
        })
        .catch((err) => {
          console.log("err", err);
        });
    }
  }
  // mounted () {
  //   console.log(this.preset)
  // }
};
</script>

<style lang="scss" scoped>
/deep/.el-switch.is-checked .el-switch__core {
  border-color: #13ce66;
  background-color: #13ce66;
}
</style>
